package com.example.stusystem.controller.Impl;

import com.example.stusystem.controller.ControllerLogic;
import com.example.stusystem.pojo.Manager;
import com.example.stusystem.pojo.Result;
import com.example.stusystem.pojo.Student;
import com.example.stusystem.service.Impl.ServiceLogicImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ControllerLogicImpl implements ControllerLogic {

    @Autowired
    ServiceLogicImpl serviceLogic;

    /**
     * 1.查询所有数据
     * @return
     */
    @Override
    @GetMapping("/selectAll")
    public Result selectAllController() {
        return Result.success(serviceLogic.selectAllService());
    }

    /**
     * 2.添加数据
     * @param student
     * @return
     */
    @PostMapping("/addOne")
    @Override
    public Result addOneController(@RequestBody Student student) {
        serviceLogic.addOneService(student);
        return Result.success(student);
    }

    /**
     * 3.删除一条数据
     * @param id
     * @return
     */
    @DeleteMapping("/deleteOne/{id}")
    @Override
    public Result deleteDataController(@PathVariable Integer id) {
        serviceLogic.deleteDataService(id);
        return Result.success();
    }

    /**
     * 4.查询一条数据
     * @param id
     * @return
     */
    @GetMapping("/selectOne/{id}")
    @Override
    public Result selectOneController(@PathVariable Integer id) {
        Student student = serviceLogic.selectOneService(id);
        return Result.success(student);
    }

    /**
     * 5.更新数据
     * @param student
     * @return
     */
    @PutMapping ("/updateStu")
    @Override
    public Result updateController(@RequestBody Student student) {
        serviceLogic.updateService(student);
        return Result.success();
    }

    /**
     * 6.校验管理员
     * @param manager
     * @return
     */
    @PostMapping("/isAdmin")
    @Override
    public Result isAdminController(@RequestBody Manager manager) {
        Manager adminService = serviceLogic.isAdminService(manager);
        return Result.success(adminService);
    }
}
